package Demo;

public class Demo03_Runnable {
    public static void main(String[] args) {
        //创建Runnable的实例
        MyRunnable01 myRunnable01 = new MyRunnable01();
        //创建线程
        Thread thread = new Thread(myRunnable01);
        //启动线程，创建PCB,参与CPU调度
        thread.start();

        //主线程的任务
        while (true){
            try {
                //让线程休息一会
                Thread.sleep(1000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            System.out.println("hello main thread...");
        }
    }
}


//单独定义了线程的任务对象
class MyRunnable01 implements Runnable{

    //实现具体的任务
    public void run(){
        while (true){
            try {
                Thread.sleep(1000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            System.out.println("hello my runnable");
        }
    }
}